package com.m3958.logcollector.datacommons.convert;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;

/**
 * @author jianglibo@gmail.com
 *         2015年11月2日
 *
 */
public class DiskFile implements Streamable {
    
    private Path path;
    
    /**
     * 
     */
    public DiskFile() {}
    
    public DiskFile(Path path) {
        this.path = path;
    }

    /* (non-Javadoc)
     * @see cc.openscanner.datacommons.convert.Streamable#getInputStream()
     */
    @Override
    public InputStream getInputStream() throws IOException {
        return Files.newInputStream(path, LinkOption.NOFOLLOW_LINKS);
    }

    /* (non-Javadoc)
     * @see cc.openscanner.datacommons.convert.Streamable#getLength()
     */
    @Override
    public long getLength() throws IOException {
        return Files.size(path);
    }
    
}
